<?php
class Update_item_model extends CI_Model{
	function __construct(){
		parent::__construct();
	}
	public function update_item(){

		$id = $this->input->post('item_id');
		$name = $this->input->post('item_name');
		$barcode = $this->input->post('item_barcode');
		$type = $this->input->post('item_type');
		$category = $this->input->post('category_name');
		$manufacturer = $this->input->post('manufacturer_name');
		$cost = $this->input->post('cost');
		$price = $this->input->post('price');
		$curr_stock = $this->input->post('curr_stock');
		$min_stock = $this->input->post('min_stock');
		$promotion_unit = $this->input->post('promotion_unit');
		$promotion_discount = $this->input->post('promotion_discount');

		if ($this->input->post('promotion_active'))
			$promotion_active = 1;
		else
			$promotion_active = 0;

		if ($this->input->post('item_active')){
			$item_active = 1;
		}else
			$item_active = 0;

		$this->load->model('manufacturer_model');
		$this->load->model('category_model');
		$this->load->model('inventory_model');
		$this->load->model('promotion_model');
		$this->load->model('item_model');

		$category_id = $this->category_model->get_id($category);
		$manufacturer_id = $this->manufacturer_model->get_id($manufacturer);

		$this->item_model->update($name, $barcode, $type, $category_id, $manufacturer_id, $cost, $price, $item_active);
		$this->inventory_model->update($id, $curr_stock, $min_stock);
		$this->promotion_model->update($id, $promotion_unit, $promotion_discount, $promotion_active);
	}
}